/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.sunspotworld;

import com.sun.spot.peripheral.Spot;
import com.sun.spot.sensorboard.EDemoBoard;
import com.sun.spot.sensorboard.peripheral.ISwitch;
import com.sun.spot.sensorboard.peripheral.ITriColorLED;
import com.sun.spot.peripheral.radio.IRadioPolicyManager;
import com.sun.spot.io.j2me.radiostream.*;
import com.sun.spot.io.j2me.radiogram.*;
import com.sun.spot.sensorboard.peripheral.ILightSensor;
import com.sun.spot.sensorboard.peripheral.LEDColor;
import com.sun.spot.util.*;

import com.wintrisstech.iaroc.irobot.IRobotCreateExtendedInterface;
import com.wintrisstech.iaroc.irobot.IRobotCreateInterface;
import com.wintrisstech.iaroc.sunspot.XLights;
import java.io.*;
import javax.microedition.io.*;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import java.util.Random;
/**
 *
 * @author Mark
 */
public class GoldRush extends Object
    {
    public GoldRush()
        {
        super();
        new BootloaderListener().start();  
        // monitor the USB (if connected) and recognize commands from host
        // cause the MIDlet to exit
        board = EDemoBoard.getInstance();
        lights = board.getLEDs();
        for (int i = 0; i < lights.length; i++)
            lights[i].setOff();
        try 
            {
            create = new IRobotCreateExtendedInterface();
            } 
        catch (IOException ex) 
            {
            ex.printStackTrace();
            }
//        create.
        }
    private void test()
        {
        for (int i = 0; true; i++)
            {
            try 
                {
               
        ITriColorLED first = lights[0];
        first.setColor(LEDColor.BLUE);
        first.setOn();
         create.driveDirect(100, -100);
                }
            catch (IOException ex) 
                {
                ex.printStackTrace();
                }
            }

        }
    public void exe()
        //executes the code for the create to do stuff
        {
        test();//runs test for now - MAV 5/27/08
        /* have a function that goes all the way to the left or right 
         * depending on which one is the closest
         * find a way to differentiate between the wall and the 
         * while (we havent gotten to the end yet)
         * if (there is a bump)
         * call the bump event handler, which:
         * turn so your at 0 theta
         * moves until there is a higher ir reading to the left meaning
         * that the wall is no longer there
         * turn to 90 theta
         * move until you past the wall using the same the thing
         * move until you bump the wall
         * then keep going straight
         * it will eventually hit the home base at the end
         * MAV 5/27/08
        */
        
        }
    public void setLEDColor(int index, LEDColor col)
        {
        ledsIndexException(index);
        lights[index].setColor(col);
        }
    
    public void ledsIndexException(int index)
        {
        if (index < -1 || index > lights.length)
            throw new ArrayIndexOutOfBoundsException("Index is out of bounds");
        return;
        }
    public ITriColorLED getLED(int index)
        {
        ledsIndexException(index);
        return lights[index];
        }
    private EDemoBoard board;
    private ITriColorLED[] lights;
    private IRobotCreateExtendedInterface create;
    }
